#include "hackathon.h"
#include <QDebug>

void Serialize::Serialization(Partie *p)
{
    QFile file("file.xml");
    file.open(QIODevice::WriteOnly);
    QDataStream out(&file);
    out << (QString) p->GetSong();
    QList<Combinaison> list = p->GetCombinaison();
    foreach (Combinaison elt, list)
    {
        out << (int) elt.GetInstant();
        out << (int) elt.GetTouche();
        out << (int) elt.GetLongueur();
    }
    //out << (QList<Combinaison>) p->GetCombinaison();
    file.close();
}

Partie Serialize::Unserialization()
{
    QFile file("file.xml");
    file.open(QIODevice::ReadOnly);
    QDataStream in(&file);
    QString song;
    QList<Combinaison> * combi = new QList<Combinaison>;
    in >> song;
    while (!file.atEnd())
    {
        int val = 0;
        int val2 = 0;
        int val3 = 0;
        in >> val >> val2 >> val3;
        qDebug() << val;
        qDebug() << val2;
        qDebug() << val3;
        Combinaison * com = new Combinaison(val, val2, val3);
        combi->append(*com);
    }
    //combi;
    Partie * partie = new Partie(song);
    partie->SetCombinaison(combi);
    file.close();
    return *partie;
}
